<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
	<link rel="stylesheet" href="../../resource/weuimin.css"/>
	<link rel="stylesheet" href="../../resource/example.css"/>
    <script type="text/javascript" src="../../script/aes.js"></script>
	<script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
	<script type="text/javascript" src="../../script/modeecb.js"></script>
	<script src="../../template/js/jquery.js"></script>
	<script src="../../template/js/com/template.js"></script>
	<script src="../../resource/my.js"></script>
	<script src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/tmd5.js"></script>
    <script type="text/javascript" src="../../script/constants.js"></script>
    <style>
    	body {
	    }
    	.bgColor {
    		
    	}
		
		.btnn{
		 width:90%;
		 font-size:20px;
		 margin:0 auto;
		 height:42px;
		 border-radius:5px;
         line-height: 42px;
		}
		.xxleft{
		  float:right;
		  margin-left:10px;
		}
		.xxrigth{
		  float:left;
		  margin-right:10px;
		}
    </style>
</head>
<body style="background: #f0f0f0"> 
<div id="zfyz" style="display:none;margin:0 auto;width:100%;height:100%;z-index: 999px; margin:0 auto;">
		<div style="">
			<div style="width:100%;clear:both">
			<div style="font-size: 20px;float:left;padding-left:10px;height:40px;line-height:40px;width:60%"><img style="width:10%;margin-right:5px" src="../../image/tl.png"/>银联支付</div>
			
			<input type="button" onclick="closeInfo()" style="height:40px;line-height:40px;font-size:xx-large;float:right;margin-right:5%;" value="&times"/>
			</div>
		</div>
<br><br><br>

</div>
<div>
	<div id="spxx">
		<div style="width:100%;clear:both">
		<div style="font-size: 20px;float:left;padding-left:10px;height:40px;line-height:40px;width:60%"><img style="width:10%;margin-right:5px" src="../../image/tl.png"/>银联支付</div>
		
		<input type="button" onclick="closeInfo()" style="height:40px;line-height:40px;font-size:xx-large;float:right;margin-right:5%;" value="&times"/>
		</div>
	</div>
	<div style="clear:both;width:100%;">
		<div style="font-size:36px;text-align:center;margin-bottom: 20px;" id="je"></div>
		<div>
		<div style="clear:both;width:100%;margin-bottom:5px;">
		<div style="float:left;margin-left:10px;font-size:15px;color:#9d9d9d">订单信息</div>
		<div style="float:right;margin-right:10px;font-size:15px;" id="spms">职场生活商品交易</div>
		</div>
         </div>
         <div>
		<div style="clear:both;width:100%;">
		<div style="float:left;margin-left:10px;font-size:16px;color:#9d9d9d">支付卡号</div>
		<div style="float:right;margin-right:10px;font-size:16px;" id="cardNo"></div>
		</div>
         </div>
				</div>
	
		</div>
		<div style="bottom:0;position:absolute;width:100%">
		<div style="text-align:center;margin-bottom:20px;">
		<div id="btnn" class="btnn" onclick="uPay();" style="background: #18b4ed;color:#fff">立即支付</div>
		</div>
		</div>
		<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../resource/jquery1.js"></script>
<script type="text/javascript">
    var orderid = "";
    var seli = 0;
    var zje = "";
    var bsh = "";
	var bdzdh = "";
	var bkhh = "";
	var bfplx = "";
	var bmc = "";
	var amc = "";
	var adh = "";
	var adz = "";
	var dzObj = null;
	var num = 0;
	var allPrice = 0;
	var allspmc = "";
	apiready = function(){
	  num = api.pageParam.num;
	  dzObj = api.pageParam.dzObj;
      orderid = api.pageParam.orderid;
      seli = api.pageParam.seli;
      zje = api.pageParam.zje;
      bsh = api.pageParam.bsh;
	  bdzdh = api.pageParam.bdzdh;
	  bkhh = api.pageParam.bkhh;
	  bfplx = api.pageParam.bfplx;
	  bmc = api.pageParam.bmc;
	  amc = api.pageParam.amc;
	  adh = api.pageParam.adh;
	  adz = api.pageParam.adz;
	  allPrice = api.pageParam.zje;
	  allspmc = api.pageParam.allspmc;
      var money = changeDecimalBuZero(allPrice,2);
	  var card = $api.getStorage("card");;
	  adz = adz.replace(/,/g,'_');
	  $("#je").html("￥"+money+"元");
	  //$("#spms").html(allspmc);
	  $("#cardNo").html(card);
	    var dl_phone = $api.getStorage("dl_phone");
	    var login = $api.getStorage("loginid");
	    var content = {"phone":dl_phone};
		//判断是否设置支付密码
		var callback = function(ret, err){
            console.log(JSON.stringify(ret));
            if(ret){
              if(JSON.stringify(ret) == "{}" || typeof(ret.pd.ZFPWZT) == "undefined"){
        		api.alert({msg:'还未设置支付密码'});
	        		api.openWin({
		                name: '个人信息',
		                url: '../userinfo_edit.html'
	                });
        	  }else{
        	      if(ret.pd.ZFPWZT=="1"){
        		}else{
	        		api.alert({msg:'还未设置支付密码'});
	        		api.openWin({
		                name: '个人信息',
		                url: '../userinfo_edit.html'
	                });
	        	}
	          }
        	}else{
        		api.alert({msg:'网络异常'});
        	}
	    }
	    encApiAjax(JSON.stringify(content),url.zfmmzt,callback);
	};
	
	function zfyz(pwd){
	var salt = api.loadSecureValue({
	       sync: true,
	       key: 'salt'
	  });
     var passwd = md5(pwd);
     var login = $api.getStorage("loginid");
	  passwd = md5(passwd+salt);
	  var phone = $api.getStorage("dl_phone");
	  var content = {"id":login,"zfpw":passwd,"phone":phone};
      var callback = function(ret, err){
	       //console.log(JSON.stringify(ret));
	      if(ret){
                if(ret.flag=="Y"){
                 unionPay();
        		}else{
        		 api.alert({msg:'密码错误'});
        		}

        	}else{
        		api.alert({msg:'网络异常'});
        	}
	  }
	  encApiAjax(JSON.stringify(content),url.cxzfmm,callback);
	 }
	
	 function uPay(){
	    api.prompt({
		  	msg: '请输入六位支付密码',
		  	type: 'password',
		    buttons: ['确定', '取消']
		}, function(ret, err) {
		    var index = ret.buttonIndex;
		    var text = ret.text;
		    if(index==1){
		     zfyz(text);
		    }
		});
     }
  
	function closeInfo(){
		if(api.systemType == "android"){
		 $api.setStorage("upay","");
		 }
		var jsfun = 'funcGoto();';
		api.execScript({
		    script: jsfun
		});
		api.closeFrame({
	    });
	    
	}
	
	
	
	var qr;
	var time;
	var amt = "";
	var orderid = "";
   	function unionPay(){
   	   	$("#loadingToast").show();
  		var _openid = $api.getStorage('openid');
  		var dl_phone = $api.getStorage("dl_phone");
  		var ip = "0.0.0.0";
        var demo = api.require('ipAddress');
		demo.getIp({
		    isNetIp: true
		},function(ret, err) {
		    console.log(JSON.stringify(ret) + "   " + JSON.stringify(err));
		    if(ret.status){
		      ip = ret.ip;
		    }
	  amt = allPrice;
      var content = {"phone":dl_phone,"dlPhone":dl_phone,"ip":ip,"deviceID":api.deviceId,"openid":_openid,"orderid":orderid,"amc":amc,"adh":adh,"adz":adz,"bmc":bmc,"bsh":bsh,
      "bdzdh":bdzdh,"bkhh":bkhh,"bfplx":bfplx,"je":allPrice};
      console.log(JSON.stringify(content));
      var callback = function(data, err){
            console.log(JSON.stringify(data));
            if("N"==data.flag){
		    	$("#loadingToast").hide();
		       if(api.systemType=='ios'){
		        api.confirm({
		          title: '温馨提示',
		          msg:'对不起，您还没绑定银行卡，请先绑定银行卡！',
		          buttons: ['去绑卡', '暂时不用']
		        }, function(ret, err) {
		          var index = ret.buttonIndex;
		          if(index==1){
		          api.openWin({
						name: 'card',
		                url:url.xzyhk+"?dlPhone="+dl_phone
		                });
		          }else if(index==2){
		            
		          }
		        });
		      }else{
		        var r=confirm("您还没有绑卡哦，确定现在去绑卡吗？");
		        if(r){
		          api.openWin({
						name: 'card',
		                url:url.xzyhk+"?dlPhone="+dl_phone
		          });
		        }else{
		          
		        }
		      }
		     }else if(data.flag == "Y"){
			       qr = data.qrNo;
			       orderid = data.payid;
			       time = setInterval("zfNotify()",2000);
			    
		     }else{
		         $("#loadingToast").hide();
		         api.alert({msg: "支付失败，暂无库存"});
		     }
      }
      encApiAjax(JSON.stringify(content),url.ylzfurl,callback);
      });
   	}
   	
  function zfNotify(){
    var callback = function(data, err){
            //console.log(JSON.stringify(data));
          if(data){
	        if (data.MSG == "成功") {	
	          var no = data.NO;
	          var je = data.AMT;
	         $("#loadingToast").hide();
	          clearInterval(time);
	          api.openWin({
	              name: 'success',
	              url: 'success.html',
	              pageParam: {
						id:orderid,
						amt:amt,
						zt:1
				  }
              });
	        }else{
	         $("#loadingToast").hide();
	          clearInterval(time);
	          var msgc = data.MSG;
	          api.openWin({
	              name: 'success',
	              url: 'success.html',
	              pageParam: {
						msg:msgc,
						zt:2
				  }
              });
	        }
        }
    }
    var content = {"qrno":qr};
    apiAjax(JSON.stringify(content),url.zczfjg,callback);
}

 function changeDecimalBuZero(number, bitNum) {  
           /// <summary>  
           /// 小数位不够，用0补足位数  
           /// </summary>  
           /// <param name="number">要处理的数字</param>  
           /// <param name="bitNum">生成的小数位数</param>  
           var f_x = parseFloat(number);  
           if (isNaN(f_x)) {  
               return 0;  
           }  
           var s_x = number.toString();  
           var pos_decimal = s_x.indexOf('.');  
           if (pos_decimal < 0) {  
               pos_decimal = s_x.length;  
               s_x += '.';  
           }  
           while (s_x.length <= pos_decimal + bitNum) {  
               s_x += '0';  
           }  
           return s_x;  
       }  
</script>
</html>